import Taro from '@tarojs/taro'
import { urlConfig } from '@config/http'

const urlName = urlConfig().baseURL
export function basRequest(url, method = 'GET', data = {}, contentType) {
  const baseUrl = urlName + url
  const header = {}
  if (contentType) header.contentType = contentType

  return new Promise((resolve, reject) => {
    Taro.request({
      url: baseUrl,
      method,
      data: data,
      header
    })
      .then(res => {
        // todo
        resolve(res.data)
      })
      .catch(err => {
        reject(err)
      })
  })
}
